<template>
  <div class="my-tag">
    <input class="input" type="text" placeholder="输入标签" 
    v-if="flag"
    :value="value"
    ref="input"
    @blur="close"
    @keyup.enter="$event.target.blur()"
    />
    <div class="text" v-else 
    @dblclick="xiuGai"
    >{{value}}</div>
  </div>
</template>

<script>
export default {
  name: "MyTag",
  components: {},
  props: {
    value:{
        type:String,
        required:true,
    }
  },
  data() {
    return {
        flag:false
    };
  },
  computed: {},
  watch: {},
  created() {},
  methods: {
    xiuGai() {
        this.flag=true
        this.$nextTick(()=>{
            this.$refs.input.focus()
        })
    },
    close(e) {
        if (e.target.value.trim()==='')  alert('请输入信息')
        else this.$emit('input',e.target.value)
        this.flag=false

    }
  },
};
</script>

<style scoped lang="less">
.my-tag {
  cursor: pointer;
  .input {
    appearance: none;
    outline: none;
    border: 1px solid #ccc;
    width: 100px;
    height: 40px;
    box-sizing: border-box;
    padding: 10px;
    color: #666;
    &::placeholder {
      color: #666;
    }
  }
}
</style>
